//
// Created by bobin on 18-7-7.
//

#include "map.pb.h"
#include <iostream>
#include "google/protobuf/io/gzip_stream.h"
#include "google/protobuf/io/zero_copy_stream.h"
#include "google/protobuf/io/coded_stream.h"
#include "google/protobuf/text_format.h"
#include "fstream"
#include "glog/logging.h"
#include <Eigen/Core>
#include <google/protobuf/io/zero_copy_stream_impl.h>
#include <google/protobuf/message.h>

using namespace std;
using namespace Eigen;

int main(int argc, char const *argv[]) {
    common::proto::MapPoint point;
    point.set_id(1);
    point.set_name("ding");
    point.set_bad(true);
    point.set_next_id(2);
    point.set_nobs(32);
    Eigen::Vector3d normal(0.1, 0.9, 0.2);
    common::proto::MatrixXd *pn = point.mutable_normal();
    pn->set_cols(1);
    pn->set_rows(3);
    for (int i = 0; i < 3; ++i) {
        pn->add_data(i);
        pn->set_data(i, normal[i]);
    }

    char desc[] = "aaa";
    point.set_orb_descriptor(desc);

    std::ofstream file_stream("test.proto", std::ofstream::out);
    if (!file_stream.is_open()) {
        LOG(INFO) << "Error writing to file" << std::endl;
        return false;
    }


    google::protobuf::io::OstreamOutputStream proto_ostream_output_stream(
            &file_stream);
    google::protobuf::TextFormat::Print(point, &proto_ostream_output_stream);

    return 0;
}
